package com.ruige.data.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruige.data.models.client.service.ISysClientService;
import com.ruige.data.models.huapu.servcie.HuapuService;
import com.ruige.data.models.huapu.servcie.HPService;
import com.ruige.data.models.local.LocalService;
import com.ruige.data.pojo.SysClient;
import com.ruige.data.pojo.SysUser;
import com.ruige.data.pojo.TbServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author huangrui
 * @Description
 * @create 2020-4-17
 */
@RestController
public class DataController {

    @Autowired
    private HuapuService huapuService;

    @Autowired
    private LocalService localService;

    @Autowired
    private HPService hpService;

    @Autowired
    private ISysClientService iSysClientService;

    @RequestMapping(value = "/hello/{page}/{size}", method = RequestMethod.GET)
    public List hello(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody(required = false) Map<String, Object> map) {
        List list = new ArrayList();
        Page<SysUser> sysUserList = huapuService.findByPage(page, size, map);
        list.add(sysUserList);
        List<TbServices> tbServicesList = localService.findAll();
        list.add(tbServicesList);
        List<SysClient> sysClientList = iSysClientService.page(new Page<>(page, size)).getRecords();
        list.add(sysClientList);
        return list;
    }

    @RequestMapping(value = "/hi/{page}/{size}", method = RequestMethod.GET)
    public List hi(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody(required = false) Map<String, Object> map) {
        Page<SysUser> pa = new Page<>(page, size);
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        if (null != map) {
            for (String s : map.keySet()) {
                wrapper.eq(null != map.get(s), s, map.get(s));
            }
        }
        Page<SysUser> sysUserPage = hpService.page(pa, wrapper);
        List<SysUser> records = sysUserPage.getRecords();
        return records;
    }


}
